#!usr/bin/python
# -*= coding: UTF-8 -*-

'''
迭代器  iter()
        __iter__()
        next()
        __next__()
'''

for i in 'Python':
    print(i)

links = {'python工作室': 'http://www.php.cn', \
         '鱼c论坛': 'https://fishc.com.cn/', \
         '鱼C博客': 'https://ilovefishc.com/', \
         '支持小鱼': 'http://www.taobao.com'
         }

for each in links:
    print('%s -> %s ' % (each, links[each]))


string = 'I love python'
it = iter(string)
print(next(it))
print(next(it))
print(next(it))
print(next(it))
print(next(it))
print(next(it))
print(next(it))

print(next(it))
print(next(it))
print(next(it))
print(next(it))
print(next(it))
print(next(it))
#print(next(it)) #超出字符串长度，没有迭代了，抛异常

string = 'love'
it = iter(string)
while True:
    try:
        each = next(it)
    except StopIteration:
        break
        print(each)  #捕获异常

for each in string:
    print(each)

class Fibs:
    def __init__(self, n = 10):
        self.a = 0
        self.b = 1
        self.n = n

    def __iter__(self):
        return self

    def __next__(self):
        self.a, self.b = self.b, self.a + self.b
        if self.a > self.n:
            raise StopIteration
        return self.a

fibs = Fibs()
for each in (fibs):
    print(each)
    '''
        if each < 20:
        print(each)
    else:
        break
    '''



